package com.fulihui.wgj.mq.kafka.producer;

import com.alibaba.fastjson.JSON;
import com.fulihui.starter.kafka.sdk.KafkaProducerSdk;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author: Levon
 * @date: 2018-06-29 14:26
 */
public abstract class AbstractProducer {

    protected static final Logger LOGGER = LoggerFactory.getLogger(KafkaProducer.class);

    KafkaProducerSdk kafkaProducerSdk;

    /**
     * kafka 消息生产
     *
     * @param topic
     * @param data
     */
    protected void send(String topic, Object data) {
        try {
            kafkaProducerSdk.send(topic, JSON.toJSONString(data));
        } catch (Exception e) {
            LOGGER.error("KafkaProducer send error,topic:" + topic, e);
        }
    }

}
